package cn.chilemou;

import com.rabbitmq.client.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import sun.plugin2.message.Message;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author LiXingShuai
 * @className AEExchange
 * @description: 备份交换器 alternate exchange
 * @date 2023年04月13日
 * @version: 1.0
 */
public class AEExchange {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = Util.getProductorConnection();
        Channel channel = connection.createChannel();

        try{
            // 定义一个正常的队列+队列
            channel.exchangeDeclare("normalExchange","direct",false);
            channel.queueDeclare("normalQueue",false,false,false,null);
            channel.queueBind("normalQueue","normalExchange","normalKey");

            // 定义一个备份交换器+对应的的队列用于存放死信
            channel.exchangeDeclare("aeChange","fanout",false);
            channel.queueDeclare("aeQueue",false,false,false,null);
            channel.queueBind("aeQueue","aeChange","");

            // 发一个正常的消息-->normalExchange-->normalQueue
            String message = "你好";
            channel.basicPublish("normalExchange","normalKey",true, MessageProperties.TEXT_PLAIN,message.getBytes());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
//            channel.close();
//            connection.close();
        }
    }

}
